<?php

class Setup_IndexController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        //$db = Zend_Db::factory($adapter);
        $db = Zend_Registry::get('cnn');
        $prefix = Zend_Registry::get('prefix');
        $dbname = Zend_Registry::get('dbname');
        $filename = realpath(dirname(__FILE__) . '/../db.sql');
        if (file_exists($filename)) {
            $sql = file_get_contents($filename);
            $sql = str_replace('chat', $dbname, $sql);
            $sql = str_replace('tb_', $prefix, $sql);
            $arr = explode(';', $sql);
            foreach ($arr as $arr)
                $db->query($arr);
            $this->view->status = 'Cài đặt hoàn tất...';
        } else {
            $this->view->status = 'Lỗi, không tìm thấy tệp dữ liệu...';
        }
    }

}